package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.interceptor.UserHolder;
import com.tanhua.server.service.CommentsService;
import com.tanhua.server.service.UserFreezeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentController {
    @Autowired
   private CommentsService commentsService;
    @Autowired
    private UserFreezeService userFreezeService;

    /*查询当前动态的评论列表*/
    //分页查询评理列表

    @GetMapping
    public ResponseEntity findComments(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize,
                                       String movementId) {
        PageResult pr = commentsService.findComments(movementId,page,pagesize);
        return ResponseEntity.ok(pr);
    }


    /*发布评论，
    *如何实现:
    *参数;movementId,comment
    * */
    @PostMapping
    public ResponseEntity saveComments(@RequestBody Map map) {
        //判断当前用户是否被冻结发表评论  2就表示冻结的范围
        userFreezeService.checkUserStatus("2", UserHolder.getUserId());


        String movementId = (String )map.get("movementId");
        String comment = (String)map.get("comment");
        commentsService.saveComments(movementId,comment);
        return ResponseEntity.ok(null);
    }
}
    /*对评论点赞*/



    /*取消点赞*/

